<template>
  <div class="app-container">
    <div class="top">
      <div class="left"><img src="@/assets/images/icon/leftIcon.png" alt="" srcset=""
          style="width: 15px;height: 14px;">我的待办</div>
      <div class="right"><el-button type="primary" size="mini" @click="addPush"
          v-hasPermi="['system:task:remove']">新建标书</el-button>
      </div>
    </div>
    <el-form :model="search" ref="search" size="small" :inline="true" label-width="90px" label-position="left">
      <el-form-item label="请输入项目名称搜索：" label-width="200px" prop="projectName">
        <el-input v-model="search.projectName" placeholder="项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="执行状态：" prop="whetherComplete">
        <el-select v-model="search.whetherComplete" placeholder="类型：">
          <el-option label="已完成" value="true">已完成</el-option>
          <el-option label="未完成" value="false">未完成</el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="类型：" prop="userName">
        <el-select v-model="form.region" placeholder="类型：">
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list.slice((pageNum - 1) * pageSize, pageNum * pageSize)" style="width: 100%;">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{ (pageNum - 1) * pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下达状态" align="center">
        <template slot-scope="scope">
          <p>已下达</p>
        </template>
      </el-table-column>
      <el-table-column label="执行状态" align="center" prop="executionStatus" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <p>{{ scope.row.whetherComplete ? '已完成' : '未完成' }}</p>
        </template>
      </el-table-column>
      <el-table-column label="下达时间" align="center" prop="createTime" />
      <el-table-column label="投标负责人" align="center" prop="headOfTenderName" :show-overflow-tooltip="true" />
      <el-table-column label="技术负责人" align="center" prop="headOfTechName" :show-overflow-tooltip="true" />
      <el-table-column label="招标平台" align="center" prop="tenderPlatformName" />
      <el-table-column label="预计竞争单位" align="center" prop="expectedCompetitor" />
      <el-table-column label="招标单位" align="center" prop="tendererName" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <!-- <el-table-column label="" align="center" prop="loginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loginTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="详情" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleForceLogout(scope.row)"
            v-hasPermi="['system:task:query']">查看详情</el-button>
          <span class="delete"> <el-button size="mini" type="text" @click="deletRow(scope.row)"
              v-hasPermi="['system:task:remove']">删除</el-button></span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="search.pageNum" :limit.sync="search.pageSize" @pagination="getList" />

    <el-dialog title="下达任务" :visible.sync="dialogFormVisible" width="30%">
      <el-form :model="form">
        <el-form-item label="名称" :label-width="formLabelWidth">
          <el-input v-model="form.projectName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="人员选择" :label-width="formLabelWidth">
          <el-select v-model="form.headOfTender" placeholder="选择人员">
            <el-option :label="i.nickName" :value="i.userId" v-for="i in userList"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结束时间" :label-width="formLabelWidth">
          <el-col :span="24">
            <el-date-picker type="date" placeholder="选择日期" v-model="form.bidDeadline" value-format="yyyy-MM-dd"
              style="width: 100%;"></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="下达意见：" :label-width="formLabelWidth">
          <el-input type="textarea" v-model="form.giveRemark"></el-input>
        </el-form-item>
        <!-- <el-form-item label="活动区域" :label-width="formLabelWidth">
          <el-select v-model="form.region" placeholder="请选择活动区域">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { myList, taskInsert, batchDelete } from "@/api/task/task";
import { getUser } from "@/api/template/template";
import { Message } from 'element-ui'
export default {
  name: "Online",
  data() {
    return {
      dialogFormVisible: false,
      search: {
        projectName: '',
        whetherComplete: false,
        pageNum: 1,
        pageSize: 10,
      },
      form: {
        headOfTender: '',//负责人
        projectName: '',
        bidDeadline: "",
        giveRemark: '',//下达意见
      },
      formLabelWidth: '120px',
      // 遮罩层
      loading: true,
      userList: [],
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      pageNum: 1,
      pageSize: 10,
    };
  },
  created() {
    this.getList();
    this.getUser()
  },
  methods: {
    deletRow(row) {
      this.$modal.confirm('是否确认删除名称为"' + row.projectName + '"的操作？').then(() => {
        return batchDelete([row.tenderId]);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    async save() {
      let res = await taskInsert(this.form)
      this.dialogFormVisible = false
      Message({ message: '保存成功', type: 'success' })
      this.getList()
    },
    async getUser() {
      let res = await getUser(this.userParams)
      this.userList = res.data
      console.log(this.userList, 'getUser')
    },
    /** 查询登录日志列表 */
    getList() {
      this.loading = true;
      myList(this.search).then(response => {
        this.list = response.rows;
        this.total = response.total;
      }).finally(()=>{
        this.loading = false;
      })
    },
    addPush() {
      this.dialogFormVisible = true;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("search");
      this.search.pageNum = 1;
      this.search.pageSize = 10;
      this.search.whetherComplete = false;
      this.handleQuery();
    },
    /** 强退按钮操作 */
    handleForceLogout(row) {
      this.$router.push({
        path: '/assignment/details',
        query: {
          tenderId: row.tenderId,
          projectName: row.projectName
        }
      })
      // this.$modal.confirm('是否确认强退名称为"' + row.userName + '"的用户？').then(function () {
      //   return forceLogout(row.tokenId);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("强退成功");
      // }).catch(() => { });
    }
  }
};
</script>

<style scoped lang="scss">
::v-deep .delete .el-button--text {
  color: #FF4431 !important;
  margin-left: 10px;
}

.top {
  display: flex;
  justify-content: space-between;
  color: #333;
  margin-bottom: 15px;

  .left {
    img {
      margin-right: 10px;
    }
  }

  .right {}
}
</style>
